package demo.practice.leetcode_offer;

import demo.practice.ListNode;

import java.util.ArrayList;
import java.util.List;

public class Offer06_2 {


    public int[] reversePrint(ListNode head) {
        List<Integer> reverse = reverse(head);
        int[] res= new int[reverse.size()];
        int count=0;
        for (Integer i : reverse) {
            res[count++]=i;
        }
        return res;
    }


    public List<Integer> reverse(ListNode head){
        //首先拿到最后一个元素
        if(head==null){
            return new ArrayList<>();
        }else {
            List<Integer> reverse = reverse(head.next);
            reverse.add(head.val);
            return reverse;
        }
    }
}
